//
//  SchoolDetailBannerTableViewCell.swift
//  HoneyBee
//
//  Created by point on 2018/6/1.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit


protocol  SchoolDetailBannerTableViewCellDelegate : class {
    func bannerCycleViewDidScrollToIndex(_ index: Int);
}




class SchoolDetailBannerTableViewCell: UITableViewCell {
    
    fileprivate lazy var bannerView =  ZCycleView()
    weak var delegate: SchoolDetailBannerTableViewCellDelegate?
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

// MARK:- 显示数据
extension SchoolDetailBannerTableViewCell : ZCycleViewProtocol{
    func cycleViewDidScrollToIndex(_ index: Int) {
   
    }
    
    
    func configModel(model:SchoolDetailModel) {
        var bannerArr = [String]()
        for cur in model.schoolDetailResourceModel {
            var str = cur.path
            if cur.fileType == 0 {
                str = cur.path + "?imageView2/2/w/\(Int(LayoutCommon.width))/h/\(Int(snapKitFit(190)))"
            }
            
            guard let codeUrlStr = str.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) else {return }
            bannerArr.append(codeUrlStr)
        }
        bannerView.setUrlsGroup(bannerArr)
    }
    
    func cycleViewDidSelectedIndex(_ index: Int) {
        delegate?.bannerCycleViewDidScrollToIndex(index)
    }
}

// MARK:- 设置UI
extension SchoolDetailBannerTableViewCell {
    fileprivate func setupUI(){
        contentView.addSubview(bannerView)
        bannerView.snp.makeConstraints { (make) in
            make.edges.equalTo(contentView)
        }
        
        bannerView.placeholderImage = UIImage(named: "")
        bannerView.pageControlItemSize = CGSize(width: 25, height: 2)
        bannerView.pageControlCurrentItemSize = CGSize(width: 25, height: 2)
        bannerView.pageControlAlignment = .center
        bannerView.pageControlIndictirColor = UIColor.init(white: 1, alpha: 0.3)
        bannerView.pageControlCurrentIndictirColor = UIColor.white
        bannerView.imageContentMode = .scaleAspectFill
        bannerView.backgroundColor = UIColor.black
        bannerView.timeInterval = 3
        bannerView.delegate = self
    }
}
